<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>gamvas.AStarGrid</title><link rel="stylesheet" type="text/css" href="../styles/main.css"><script language=JavaScript src="../javascript/main.js"></script><script language=JavaScript src="../javascript/prettify.js"></script><script language=JavaScript src="../javascript/searchdata.js"></script></head><body class="ContentPage" onLoad="NDOnLoad();prettyPrint();"><script language=JavaScript><!--
if (browserType) {document.write("<div class=" + browserType + ">");if (browserVer) {document.write("<div class=" + browserVer + ">"); }}// --></script>

<!--  Generated by Natural Docs, version 1.51 -->
<!--  http://www.naturaldocs.org  -->

<!-- saved from url=(0026)http://www.naturaldocs.org -->




<div id=Content><div class="CClass"><div class=CTopic id=MainTopic><h1 class=CTitle><a name="gamvas.AStarGrid"></a>gamvas.<wbr>AStarGrid</h1><div class=CBody><h4 class=CHeading>Description</h4><p>A class to simplify A* pathfinding on a 2x2 grid with a optional height field</p><p>The single fields can have any value where negative values mean &lsquo;not walkable&rsquo; and positive values are interpreted debending on the path finding strategy used</p><h4 class=CHeading>Constructor</h4><p>new gamvas.AStarGrid(w, h, diag, withFirst, strt, dflt);</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>w</td><td class=CDLDescription>The width of the grid</td></tr><tr><td class=CDLEntry>h</td><td class=CDLDescription>The height of the grid</td></tr><tr><td class=CDLEntry>diag</td><td class=CDLDescription>Allow diagonal steps (optional, default: false)</td></tr><tr><td class=CDLEntry>withFirst</td><td class=CDLDescription>Include the first node of the path in the result (optional, default: true)</td></tr><tr><td class=CDLEntry>strt</td><td class=CDLDescription>The path finding strategy (see below) (optional)</td></tr><tr><td class=CDLEntry>dflt</td><td class=CDLDescription>The default value for the grid fields (optional, default: 0)</td></tr></table><h4 class=CHeading>Extends</h4><p><a href="gamvas-astarmap-js.html#gamvas.AStarMap" class=LClass id=link4 onMouseOver="ShowTip(event, 'tt4', 'link4')" onMouseOut="HideTip('tt4')">gamvas.AStarMap</a></p><h4 class=CHeading>Strategy</h4><p>There are several strategies, how the values are interpreted.&nbsp; They only give minor differnce in the result, but in certain situations it might be necessary to use a different strategy</p><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>gamvas.AStar.STRATEGY_AVOID_STEPS</td><td class=CDLDescription>(default) The algorithm tries to avoid height differences, so if you start in a valley, it will try to stay in the valley and run around mountains, until there is nothing left other then stepping on a mountain, once on the moutain, it tries to stay on it, until it has to go down to the valley again.</td></tr><tr><td class=CDLEntry>gamvas.AStar.STRATEGY_IGNORE_STEPS</td><td class=CDLDescription>The algorithm completely ignores height information and always tries to go straight to the target</td></tr></table><h4 class=CHeading>Example</h4><p>The following would create a grid with 50 by 50 fields.&nbsp; As we do not set any field values, default is 0, which means perfect ground to walk on, this example would result in a path that represents a straight line from upper left to lower right corner of the grid.</p><blockquote><pre>var pathMap = new gamvas.AStarGrid(50, 50);
var result = pathMap.find(0, 0, 49, 49);
for (var i = 0; i &lt; result.length; i++) {
   console.log('Step '+i+' is at 'result[i].position.x+','+result[i].position.y);
}</pre></blockquote><h4 class=CHeading>See</h4><p><a href="gamvas-astar-js.html#gamvas.AStar" class=LClass id=link5 onMouseOver="ShowTip(event, 'tt5', 'link5')" onMouseOut="HideTip('tt5')">gamvas.AStar</a></p><!--START_ND_SUMMARY--><div class=Summary><div class=STitle>Summary</div><div class=SBorder><table border=0 cellspacing=0 cellpadding=0 class=STable><tr class="SMain"><td class=SEntry><a href="#gamvas.AStarGrid" >gamvas.<wbr>AStarGrid</a></td><td class=SDescription>A class to simplify A* pathfinding on a 2x2 grid with a optional height field</td></tr><tr class="SGroup SIndent1"><td class=SEntry><a href="#gamvas.AStarGrid.Functions" >Functions</a></td><td class=SDescription></td></tr><tr class="SFunction SIndent2 SMarked"><td class=SEntry><a href="#gamvas.AStarGrid.setValue" id=link1 onMouseOver="ShowTip(event, 'tt1', 'link1')" onMouseOut="HideTip('tt1')">setValue</a></td><td class=SDescription>Set a value val in the grid on position x, y</td></tr><tr class="SFunction SIndent2"><td class=SEntry><a href="#gamvas.AStarGrid.getValue" id=link2 onMouseOver="ShowTip(event, 'tt2', 'link2')" onMouseOut="HideTip('tt2')">getValue</a></td><td class=SDescription>Get the field value of position x,y in the grid</td></tr><tr class="SFunction SIndent2 SMarked"><td class=SEntry><a href="#gamvas.AStarGrid.find" id=link3 onMouseOver="ShowTip(event, 'tt3', 'link3')" onMouseOut="HideTip('tt3')">find</a></td><td class=SDescription>Find a path between two positions in the grid</td></tr></table></div></div><!--END_ND_SUMMARY--></div></div></div>

<div class="CGroup"><div class=CTopic><h3 class=CTitle><a name="gamvas.AStarGrid.Functions"></a>Functions</h3></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="gamvas.AStarGrid.setValue"></a>setValue</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>setValue: function(</td><td class="PParameter  prettyprint " nowrap>x,</td></tr><tr><td></td><td class="PParameter  prettyprint " nowrap>y,</td></tr><tr><td></td><td class="PParameter  prettyprint " nowrap>val</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p>Set a value val in the grid on position x, y</p><h4 class=CHeading>Description</h4><p>Negative values are &lsquo;not walkable&rsquo; while values of 0 or higher are &lsquo;walkable&rsquo; where depending on the strategy the positive values may be interpreted as height map</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>x</td><td class=CDLDescription>The x position in the grid</td></tr><tr><td class=CDLEntry>y</td><td class=CDLDescription>The y position in the grid</td></tr><tr><td class=CDLEntry>val</td><td class=CDLDescription>The value, where &lt; 0 means &lsquo;not walkable&rsquo; and &gt;= 0 means &lsquo;walkable&rsquo;</td></tr></table></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="gamvas.AStarGrid.getValue"></a>getValue</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>getValue: function(</td><td class="PParameter  prettyprint " nowrap>x,</td></tr><tr><td></td><td class="PParameter  prettyprint " nowrap>y</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p>Get the field value of position x,y in the grid</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>x</td><td class=CDLDescription>The x position in the grid</td></tr><tr><td class=CDLEntry>y</td><td class=CDLDescription>The y position in the grid</td></tr></table></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="gamvas.AStarGrid.find"></a>find</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>find: function(</td><td class="PParameter  prettyprint " nowrap>xs,</td></tr><tr><td></td><td class="PParameter  prettyprint " nowrap>ys,</td></tr><tr><td></td><td class="PParameter  prettyprint " nowrap>xe,</td></tr><tr><td></td><td class="PParameter  prettyprint " nowrap>ye</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p>Find a path between two positions in the grid</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>xs</td><td class=CDLDescription>The x position of the start field</td></tr><tr><td class=CDLEntry>ys</td><td class=CDLDescription>The y position of the start field</td></tr><tr><td class=CDLEntry>xe</td><td class=CDLDescription>The x position of the end field (aka target)</td></tr><tr><td class=CDLEntry>ye</td><td class=CDLDescription>The y position of the end field (aka target)</td></tr></table><h4 class=CHeading>Returns</h4><p>An array of <a href="gamvas-astargridnode-js.html#gamvas.AStarGridNode" class=LClass id=link6 onMouseOver="ShowTip(event, 'tt6', 'link6')" onMouseOut="HideTip('tt6')">gamvas.AStarGridNode</a>.&nbsp; If no path is possible, the array has a length of 0</p></div></div></div>

</div><!--Content-->


<div id=Footer><a href="http://www.naturaldocs.org">Generated by Natural Docs</a></div><!--Footer-->


<div id=Menu><div class=MEntry><div class=MFile><a href="gamvas-base-js.html">gamvas</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-actor-js.html">gamvas.<wbr>Actor</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-actorstate-js.html">gamvas.<wbr>ActorState</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-animation-js.html">gamvas.<wbr>Animation</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-astar-js.html">gamvas.<wbr>AStar</a></div></div><div class=MEntry><div class=MFile id=MSelected>gamvas.<wbr>AStarGrid</div></div><div class=MEntry><div class=MFile><a href="gamvas-astargridnode-js.html">gamvas.<wbr>AStarGridNode</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-astarmap-js.html">gamvas.<wbr>AStarMap</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-astarnode-js.html">gamvas.<wbr>AStarNode</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-camera-js.html">gamvas.<wbr>Camera</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-class-js.html">gamvas.<wbr>Class</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-config-js.html">gamvas.<wbr>config</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-dom-js.html">gamvas.dom</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-event-js.html">gamvas.<wbr>event</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-image-js.html">gamvas.<wbr>Image</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-key-js.html">gamvas.key</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-math-js.html">gamvas.math</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-mouse-js.html">gamvas.<wbr>mouse</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-particleemitter-js.html">gamvas.<wbr>ParticleEmitter</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-physics-js.html">gamvas.<wbr>physics</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-physics-userdata-js.html">gamvas.<wbr>physics.<wbr>UserData</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-rect-js.html">gamvas.Rect</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-resource-js.html">gamvas.<wbr>Resource</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-screen-js.html">gamvas.<wbr>screen</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-sound-js.html">gamvas.<wbr>Sound</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-state-js.html">gamvas.<wbr>state</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-state-state-js.html">gamvas.<wbr>State</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-timer-js.html">gamvas.<wbr>timer</a></div></div><div class=MEntry><div class=MFile><a href="gamvas-vector2d-js.html">gamvas.<wbr>Vector2D</a></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent1')">Index</a><div class=MGroupContent id=MGroupContent1><div class=MEntry><div class=MIndex><a href="../index/General.html">Everything</a></div></div><div class=MEntry><div class=MIndex><a href="../index/Classes.html">Classes</a></div></div><div class=MEntry><div class=MIndex><a href="../index/Functions.html">Functions</a></div></div><div class=MEntry><div class=MIndex><a href="../index/Macros.html">Macros</a></div></div><div class=MEntry><div class=MIndex><a href="../index/Variables.html">Variables</a></div></div></div></div></div><script type="text/javascript"><!--
var searchPanel = new SearchPanel("searchPanel", "HTML", "../search");
--></script><div id=MSearchPanel class=MSearchPanelInactive><input type=text id=MSearchField value=Search onFocus="searchPanel.OnSearchFieldFocus(true)" onBlur="searchPanel.OnSearchFieldFocus(false)" onKeyUp="searchPanel.OnSearchFieldChange()"><select id=MSearchType onFocus="searchPanel.OnSearchTypeFocus(true)" onBlur="searchPanel.OnSearchTypeFocus(false)" onChange="searchPanel.OnSearchTypeChange()"><option  id=MSearchEverything selected value="General">Everything</option><option value="Classes">Classes</option><option value="Functions">Functions</option><option value="Macros">Macros</option><option value="Variables">Variables</option></select></div><script language=JavaScript><!--
HideAllBut([], 2);// --></script></div><!--Menu-->



<!--START_ND_TOOLTIPS-->
<div class=CToolTip id="tt1"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>setValue: function(</td><td class="PParameter  prettyprint " nowrap>x,</td></tr><tr><td></td><td class="PParameter  prettyprint " nowrap>y,</td></tr><tr><td></td><td class="PParameter  prettyprint " nowrap>val</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote>Set a value val in the grid on position x, y</div></div><div class=CToolTip id="tt2"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>getValue: function(</td><td class="PParameter  prettyprint " nowrap>x,</td></tr><tr><td></td><td class="PParameter  prettyprint " nowrap>y</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote>Get the field value of position x,y in the grid</div></div><div class=CToolTip id="tt3"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>find: function(</td><td class="PParameter  prettyprint " nowrap>xs,</td></tr><tr><td></td><td class="PParameter  prettyprint " nowrap>ys,</td></tr><tr><td></td><td class="PParameter  prettyprint " nowrap>xe,</td></tr><tr><td></td><td class="PParameter  prettyprint " nowrap>ye</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote>Find a path between two positions in the grid</div></div><div class=CToolTip id="tt4"><div class=CClass>A flexible 3D node based A* pathfinding system</div></div><div class=CToolTip id="tt5"><div class=CClass>gamvas.AStar specific defines, variables and functions</div></div><div class=CToolTip id="tt6"><div class=CClass>The node information of a gamvas.AStarGrid map</div></div><!--END_ND_TOOLTIPS-->




<div id=MSearchResultsWindow><iframe src="" frameborder=0 name=MSearchResults id=MSearchResults></iframe><a href="javascript:searchPanel.CloseResultsWindow()" id=MSearchResultsWindowClose>Close</a></div>


<script language=JavaScript><!--
if (browserType) {if (browserVer) {document.write("</div>"); }document.write("</div>");}// --></script></body></html>